define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Panicauction_pinfo, $ionicSlideBoxDelegate, $stateParams, GoPage, $sce, $timeout, GoDialog, $ionicPopup, $ionicPopover,$window) {
		$scope.act_id = $stateParams.act_id;
		$scope.slideIndex = $stateParams.id;
		$scope.product_id = $stateParams.product_id;
		$scope.is_price = $stateParams.is_price;
		$scope.selectTab = 0;
		$scope.count = null;
		$scope.input = new Array();
		$scope.is_click = false;
		$scope.is_show = new Array();
		$scope.image = './img/auction/plc.jpg';
		//页面激活
		$scope.$on('$ionicView.afterEnter', function() {
			var lan = 0; //这是状态栏，只有ios的APP才有
		var tab = 0;
		var bars = document.getElementById("nav-bar-title");
		var bar = ((bars != undefined) ? 44 : 0);
		if(window.cordova && window.cordova.plugins && ionic.Platform.isIOS()) { lan = 20; }
		//整体高度
		var all = $window.innerHeight;
		var pc_pinfo = document.getElementById("pc-pinfo").clientHeight;
		$scope.myObj = { //滚动条可视范围
			"height": all - lan - bar - tab -pc_pinfo + "px"
		};
			//滑动切换
			if($scope.slideIndex != undefined) {
				$scope.selectTab = $scope.slideIndex;
			};
			$ionicSlideBoxDelegate.$getByHandle('tab-handle').slide($scope.selectTab);
			$scope.init_data();
		}, false);
		$ionicPopover.fromTemplateUrl('templates/modal/image.html', {
			scope: $scope
		}).then(function(popover) {
			$scope.popover = popover;
		});
		$scope.showBigImage = function(url) {
			//    $scope.bigImagesUrl = url;
			$scope.show_image = $scope.image
			$scope.popover.show();
			//    $cordovaStatusbar.hide();
		};
		var myPopup;
		$scope.showPopup = function(src) { //绑定数据时要注意，如果是数组，则通过$index传入下标；如果是json，则传入key
			$scope.show_image = src;
			myPopup = $ionicPopup.show({ //show()
				templateUrl: 'templates/modal/image.html',
				//					title: "制造商详情",
				scope: $scope, //绑定数据，必须写这行
				buttons: [{
					text: "返回",
					type: "button-assertive",
					onTap: function() { // 当点击保存按钮时，执行该函数
						//						console.log($scope.scope.reason);
						//return $scope.scope.reason;//
					}
				}]
			});

		}
		$scope.activeTab = function(index) {
			$scope.selectTab = index;
			$ionicSlideBoxDelegate.$getByHandle('tab-handle').slide(index);
		};
		//滑动切换
		$scope.slideChanged = function(index) {
			$scope.selectTab = index;
		};
		//加载数据
		$scope.init_data = function() {
			$scope.index = '';
			Panicauction_pinfo.get_description($scope.act_id, $scope.product_id, function(data) {
				console.log(data)
					//				$scope.rule = data.result.rule;
				$scope.description = $sce.trustAsHtml(data.result.description);
				$scope.bn = data.result.bn;
				$scope.product_bn = data.result.product_bn;
				$scope.brand = data.result.brand;
				var logs = data.result.act_logs;
				for(var i=0;i<logs.length;i++){
					var length = logs[i].login_name.length;
					var sub = logs[i].login_name.substring(1,length-1);
					var subLength = sub.length;
					var replaceStr = "";
					for(var j=0;j<subLength;j++){
						replaceStr +='*';
					}
					logs[i].login_name = logs[i].login_name.replace(sub,replaceStr);
				}
				$scope.act_logs = logs;
			})
		};
		//点击其他区域关闭弹出窗       
		var htmlEl = angular.element(document.querySelector('html'));
		htmlEl.on('click', function(event) {　　
			console.log(event.target.nodeName);
			if(event.target.nodeName === 'DIV'||event.target.nodeName === 'ION-SCROLL') {　　　　
				if($scope.popover) {　　　　　　
					$scope.popover.hide();　　　　
				}　　　　　
			}
		});

	}

	controller.$inject = ['$scope', 'Panicauction_pinfo', '$ionicSlideBoxDelegate', '$stateParams', 'GoPage', '$sce', '$timeout', 'GoDialog', '$ionicPopup', '$ionicPopover','$window'];

	return app.registerController("panicauction_pinfoctrl", controller);
});